package com.samxcode.leetcode;

public class ListNode {

    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }
    
    public static ListNode generateListNode(int n) {
        ListNode head = new ListNode(0);
        ListNode node = head;
        for (int i = 1; i <= n; i++) {
            node.next = new ListNode(i);
            node = node.next;
        }
        return head.next;
    }
    
    public static void printListNode(ListNode node) {
        while (node != null) {
            System.out.print(node.val + " ");
            node = node.next;
        }
    }
    
    @Override
    public String toString() {
        return String.valueOf(val);
    }

}
